﻿using System.Windows;
using System.Windows.Input;

namespace VNet.VisiSuite.Controls
{
    /// <summary>
    ///     Interaction logic for FindBox.xaml
    /// </summary>
    public partial class FindBox
    {
        public delegate void OnEnterKey(string text);

        private OnEnterKey _on_enter_key;

        public FindBox()
        {
            InitializeComponent();
        }

        public void clear()
        {
            _find.Clear();
#if DEBUG
            _find.Text = "36691313";
#endif
        }

        public void focus()
        {
            _find.Focus();
            if (!_find.IsKeyboardFocused)
                Keyboard.Focus(_find);
        }

        public void onEnterKey(OnEnterKey on_enter_key)
        {
            _on_enter_key = on_enter_key;
        }

        private void onKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Return && _on_enter_key != null)
            {
                _on_enter_key(_find.Text.Trim());
            }
        }

        private void onLoaded(object sender, RoutedEventArgs e)
        {
            _find.Focus();
        }
    }
}